package com.module.overview.ui.cardHistoryDetails.provider

import android.graphics.Typeface
import android.util.Log
import android.widget.TextView
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.overView.HistoryDetailsModel
import com.common.app.utls.TimeUtils
import com.common.app.utls.TimeUtils.calculateTimeBreakpoints
import com.common.app.utls.TimeUtils.calculateTimeBreakpointsRounded
import com.common.base.app.extras.doOnIOThread
import com.common.base.app.extras.doOnUiThread
import com.common.base.app.extras.no
import com.common.base.app.extras.otherwise
import com.common.base.app.extras.yes
import com.common.base.utils.AppUtils
import com.common.base.utils.JsonUtils
import com.common.base.utils.LogUtils
import com.common.base.utils.MathUtil
import com.common.base.utils.SpanUtils
import com.common.base.utils.ViewUtils
import com.common.base.utils.ViewUtils.getColor
import com.common.base.utils.ViewUtils.getString
import com.module.ble.data.bean.CusChartData
import com.module.ble.db.table.UserSleepInfo
import com.module.ble.repo.HeartRateRepo
import com.module.ble.repo.SleepInfoRepo
import com.module.ble.repo.BloodOxygenRepo
import com.module.ble.repo.BodyTemperatureRepo
import com.module.ble.repo.HeartRateVariabilityRepo
import com.module.ble.repo.RespiratoryRateRepo
import com.module.ble.utils.AllCardTypeConfig
import com.module.ble.utils.groupSleepDataByQualityAndTime
import com.module.ble.widget.CandlestickChart
import com.module.ble.widget.SleepHrCurveChart
import com.module.ble.widget.SleepHrCurveNewChart
import com.module.ble.widget.SleepHrvCandlestickChart
import com.module.ble.widget.SleepOptimalRangeProgressBar
import com.module.ble.widget.SleepStageChart
import com.module.overview.R
import kotlin.random.Random

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/7/11
 *
 * 描述：睡眠时段卡片
 *
 * 修订历史：完成度100%
 *
 */
class OvSleepPeriodCardProvider(time:Long,
    override val itemViewType: Int = AllCardTypeConfig.TYPE_CARD_SLEEP_TOTAL_PERIOD,
    override val layoutId: Int = R.layout.overview_sleep_period_crad_provider
) : BaseItemProvider<HistoryDetailsModel>() {

    private val sleepData = mutableListOf<CusChartData>()

    var points = mutableListOf<String>()

    private val sleepHrvCurveData = mutableListOf<CusChartData>()
    private var sleepHrCurveChart: SleepHrCurveChart? = null
    private var tvSleepHrAverage: TextView? = null
    private var tvSleepHrPast7nights: TextView? = null


    private val sleepHrvCandlestickData = mutableListOf<CusChartData>()
    private var sleepHrvCandlestickChart: SleepHrvCandlestickChart? = null
    private var tvSleepHrvAverage: TextView? = null
    private var tvSleepHrvPast7nights: TextView? = null

    private var sleepOxyCurveChart: SleepHrCurveChart? = null
    private var tvSleepOxyAverage: TextView? = null
    private var tvSleepOxyPast7nights: TextView? = null


    private var tvTempTheDayAverage: TextView? = null
    private var tvRefTemp: TextView? = null
    private var tvTempDif: TextView? = null

    private var tvResRateAverage: TextView? = null
    private var tvResRateScope: TextView? = null
    private var tvResRateAvg7days: TextView? = null

    private var curTime = time

    private val curTimePair = TimeUtils.getTimeRangeForSleep(curTime)

    var totalDuration = 0L//睡眠总时长，单位：分钟
    var awakeDuration = 0L//清醒时长，单位：分钟
    var lightDuration = 0L//浅睡时长，单位：分钟
    var remDuration = 0L//快速眼动时长，单位：分钟
    var deepDuration = 0L//深睡时长，单位：分钟

    var hrSpliceHint = getString(R.string.common_times_per_minute_splice)
    var averageSpliceHint = getString(R.string.common_average_unit)
    var sevenDayAverageHint = getString(R.string.common_avg_7days_tips)

    var theDayStayBedDuration = 0L//卧床总时长，单位：分钟
    var theDaySleepEfficiency = 0//睡眠效率

    val sleepDurationLowTemp = 21_600_000
    val sleepDurationHighTemp = 36_000_000
    val sleepEfficiencyLowTemp = 80
    val sleepEfficiencyHighTemp = 100

    init {
        val currentTime = System.currentTimeMillis()
        val startOfDay = currentTime - (currentTime % (24 * 60 * 60 * 1000)) // 当天0点时间戳

        for (index in 0 until 37) {
            val timeOffset = index * 30 * 60 * 1000L // 每30分钟的时间偏移
            val timestamp = startOfDay + timeOffset

            // 根据实际压力数据设置值（0-100）
            val minValue = when {
                index < 12 -> (10 + (30..70).random()).toFloat() // 0-6点
                index < 24 -> (30..80).random().toFloat() // 6-12点
                else -> (30..80).random().toFloat() // 12-24点
            }

            sleepHrvCandlestickData.add(
                CusChartData(
                    createdTime = timestamp,
                    minValue = (30..minValue.toInt()).random().toFloat(),
                    mValue = minValue,
                    dayNum = 0
                )
            )
        }

        for (index in 0 until 19) {
            val timeOffset = index * 30 * 60 * 1000L // 每30分钟的时间偏移
            val timestamp = startOfDay + timeOffset

            // 根据实际压力数据设置值（0-100）
            val minValue = when {
                index < 12 -> (90..97).random().toFloat() // 0-6点
                index < 24 -> (90..92).random().toFloat() // 6-12点
                else -> (93..100).random().toFloat() // 12-24点
            }

            sleepHrvCurveData.add(
                CusChartData(
                    createdTime = timestamp,
                    minValue = 0f,
                    mValue = minValue,
                    dayNum = 0
                )
            )
        }


//        sleepHrCurveData[0].minValue = 20f
//        sleepHrCurveData[0].mValue = 110f
    }

    override fun convert(helper: BaseViewHolder, item: HistoryDetailsModel) {
        helper.setText(R.id.tvTotalDurationHint, "${getString(R.string.overview_sleep_duration_hint)}${getString(R.string.overview_sleep_duration_reference_hint)}")
        helper.setText(R.id.tvStayDurationHint, "${getString(R.string.overview_stay_duration_hint)}${getString(R.string.overview_sleep_stay_edy_duration_reference_hint)}")
        helper.setText(R.id.tvSleepEfficiencyHint, "${getString(R.string.overview_sleep_efficiency_hint)}${getString(R.string.overview_sleep_efficiency_reference_hint)}")

        val sleepStageChart = helper.getView<SleepStageChart>(R.id.sleepStageChart)

        // 设置数据
        sleepStageChart.setRowCount(4)
//        sleepStageChart.setSleepStageData(sleepData)

        // 设置触摸监听
        sleepStageChart.setOnSleepStageTouchListener (object :
            SleepStageChart.OnSleepStageTouchListener{
            override fun onStageTouch(stageData: CusChartData, stageName: String) {
                // 处理触摸事件
                Log.d("SleepChart", "触摸了 $stageName，时长：${stageData.timeLong}分钟")
                helper.setGone(R.id.tvSleepStaging,false)
                helper.setText(R.id.tvSleepStaging,"${stageName}时长：${stageData.timeLong}分钟")
            }

            override fun onTouchReleased() {
                helper.setGone(R.id.tvSleepStaging,true)

            }

        })

//        sleepHrCurveChart?.setYRangeBackground(startValue = 55f,endValue = 65f,backgroundColor = getColor(R.color.c_f7ebf2))
//        sleepHrCurveChart?.setTimeLabels(points)
//        // 设置Y轴阶段
//        sleepHrCurveChart?.setYAxisStages(
//            floatArrayOf(30f, 65f, 120f), // 阶段分界点
//        )
//        sleepHrCurveChart?.setBasicValue(75f)
//        sleepHrCurveChart?.setData(sleepHrvCandlestickData)

//        sleepHrvCandlestickData[6].selectBg = true
//        sleepHrvCandlestickData[7].selectBg = true
//        sleepHrvCandlestickData[9].selectBg = true
//        sleepHrvCandlestickData[11].selectBg = true
//        val pointsTemp = calculateTimeBreakpointsRounded(1748447520000, 1748476500000) as MutableList<String>
//        sleepHrvCandlestickChart?.setTimeLabels(pointsTemp)
//        // 设置Y轴阶段
//        sleepHrvCandlestickChart?.setYAxisStages(
//            floatArrayOf(0f, 70f, 150f), // 阶段分界点
//        )
//        sleepHrvCandlestickChart?.setBasicValue(55f)
//        sleepHrvCandlestickChart?.setData(sleepHrvCandlestickData)

//        sleepOxyCurveChart?.setYRangeBackground(startValue = 95f,endValue = 100f,backgroundColor = getColor(R.color.c_f7ebf6))
//        sleepOxyCurveChart?.setTimeLabels(points)
//        // 设置Y轴阶段
//        sleepOxyCurveChart?.setYAxisStages(
//            floatArrayOf(90f, 95f, 100f), // 阶段分界点
//        )
//        sleepOxyCurveChart?.setBasicValue(97f)
//        sleepOxyCurveChart?.setData(sleepHrvCurveData)

        getSevenNightsDayHr()

        doOnIOThread {
            SleepInfoRepo.instance.findByTimeRangeByNight(curTimePair.first, curTimePair.second)?.let {listIt->
//                val listItStr = JsonUtils.toJson(listIt)
//                val listIt: List<UserSleepInfo> = JsonUtils.fromJsonList("[{\"createdTime\":1755792840000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792840000,\"sleepQuality\":2},{\"createdTime\":1755792900000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792900000,\"sleepQuality\":2},{\"createdTime\":1755792960000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792960000,\"sleepQuality\":2},{\"createdTime\":1755796620000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796620000,\"sleepQuality\":2},{\"createdTime\":1755796680000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796680000,\"sleepQuality\":2},{\"createdTime\":1755797880000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755797880000,\"sleepQuality\":2},{\"createdTime\":1755798180000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798180000,\"sleepQuality\":2},{\"createdTime\":1755798060000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798060000,\"sleepQuality\":3},{\"createdTime\":1755798480000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798480000,\"sleepQuality\":3}]")
//                val listIt: List<UserSleepInfo> = JsonUtils.fromJsonList("[{\"createdTime\":1755792060000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792840000,\"sleepQuality\":-2},{\"createdTime\":1755792840000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792840000,\"sleepQuality\":2},{\"createdTime\":1755792900000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792900000,\"sleepQuality\":2},{\"createdTime\":1755792960000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792960000,\"sleepQuality\":2},{\"createdTime\":1755796620000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796620000,\"sleepQuality\":2},{\"createdTime\":1755796680000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796680000,\"sleepQuality\":2},{\"createdTime\":1755797880000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755797880000,\"sleepQuality\":2},{\"createdTime\":1755798180000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798180000,\"sleepQuality\":2},{\"createdTime\":1755798060000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798060000,\"sleepQuality\":3},{\"createdTime\":1755798480000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798480000,\"sleepQuality\":3}]")
//                val listIt: List<UserSleepInfo> = JsonUtils.fromJsonList("[{\"createdTime\":1755792060000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792060000,\"sleepQuality\":-2},{\"createdTime\":1755792840000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792840000,\"sleepQuality\":2},{\"createdTime\":1755792900000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792900000,\"sleepQuality\":2},{\"createdTime\":1755792960000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755792960000,\"sleepQuality\":2},{\"createdTime\":1755796620000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796620000,\"sleepQuality\":2},{\"createdTime\":1755796680000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755796680000,\"sleepQuality\":2},{\"createdTime\":1755797880000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755797880000,\"sleepQuality\":2},{\"createdTime\":1755798180000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798180000,\"sleepQuality\":2},{\"createdTime\":1755798060000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798060000,\"sleepQuality\":3},{\"createdTime\":1755798480000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798480000,\"sleepQuality\":3},{\"createdTime\":1755798600000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755798600000,\"sleepQuality\":-2},{\"createdTime\":1755799200000,\"endTime\":0,\"firmName\":\"2\",\"inDateTime\":1755799200000,\"sleepQuality\":-2}]")
//                val listIt: List<UserSleepInfo> = JsonUtils.fromJsonList("[{\"createdTime\":1755792060000,\"endTime\":0,\"firmName\":\"2025-08-22 00:01:00\",\"sleepQuality\":-2},{\"createdTime\":1755792840000,\"endTime\":0,\"firmName\":\"2025-08-22 00:14:00\",\"sleepQuality\":2},{\"createdTime\":1755792900000,\"endTime\":0,\"firmName\":\"2025-08-22 00:15:00\",\"sleepQuality\":2},{\"createdTime\":1755792960000,\"endTime\":0,\"firmName\":\"2025-08-22 00:16:00\",\"sleepQuality\":2},{\"createdTime\":1755796620000,\"endTime\":0,\"firmName\":\"2025-08-22 01:17:00\",\"sleepQuality\":2},{\"createdTime\":1755796680000,\"endTime\":0,\"firmName\":\"2025-08-22 01:18:00\",\"sleepQuality\":2},{\"createdTime\":1755797880000,\"endTime\":0,\"firmName\":\"2025-08-22 01:38:00\",\"sleepQuality\":2},{\"createdTime\":1755798180000,\"endTime\":0,\"firmName\":\"2025-08-22 01:43:00\",\"sleepQuality\":2},{\"createdTime\":1755798060000,\"endTime\":0,\"firmName\":\"2025-08-22 01:41:00\",\"sleepQuality\":3},{\"createdTime\":1755798480000,\"endTime\":0,\"firmName\":\"2025-08-22 01:48:00\",\"sleepQuality\":3},{\"createdTime\":1755798600000,\"endTime\":0,\"firmName\":\"2025-08-22 01:50:00\",\"sleepQuality\":-2},{\"createdTime\":1755799200000,\"endTime\":0,\"firmName\":\"2025-08-22 02:00:00\",\"sleepQuality\":-2}]")

                listIt.sortedBy { it.createdTime }//按时间排序（升序）
                listIt.isNullOrEmpty().no {
                    val commonPoints = calculateTimeBreakpointsRounded(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0) as MutableList<String>
                    doOnUiThread {
                        sleepHrCurveChart?.setTimeLabels(commonPoints)
                        sleepHrvCandlestickChart?.setTimeLabels(commonPoints)
                        sleepOxyCurveChart?.setTimeLabels(commonPoints)
                    }

                    getSleepTheDayHr(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0)
                    getTheDayHrvData(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0)
                    getTheDayOxyData(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0)
                    getTheDayBodyTempData(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0)
                    getTheDayResRateData(listIt.firstOrNull()?.createdTime?:0,listIt.lastOrNull()?.createdTime?:0)
                }
//                LogUtils.d("OvSleepPeriodCardProvider", "YQ: allSleepData ${JsonUtils.toJson(listIt)}")
                initClassDuration()

                sleepData.clear()
                if (listIt.isNotEmpty()) {
                    val groupedSleepData = groupSleepDataByQualityAndTime(listIt)
                    sleepData.addAll(groupedSleepData)
                    sleepData.forEach {sleepDataIt->
                        totalDuration += if (sleepDataIt.status==1||sleepDataIt.status==2||sleepDataIt.status==3) sleepDataIt.timeLong else 0
                        theDayStayBedDuration += sleepDataIt.timeLong
                        when (sleepDataIt.status) {// 睡眠质量 0,清醒(离床) 1:快速眼动 2:浅睡 3:深睡 4:卧床 5:未佩戴 101:小睡（自用） -999：未知（自用）
                            0 -> awakeDuration += sleepDataIt.timeLong  // 清醒
                            1 -> remDuration += sleepDataIt.timeLong    // 快速眼动
                            2 -> lightDuration += sleepDataIt.timeLong  // 浅睡
                            3 -> deepDuration += sleepDataIt.timeLong   // 深睡
                        }
                    }

                    theDaySleepEfficiency = ((MathUtil.div(totalDuration.toString(),theDayStayBedDuration.toString(),false)?:"0").toFloat() * 100).toInt()

                    points = calculateTimeBreakpointsRounded(listIt.first().createdTime, listIt.last().createdTime) as MutableList<String>
                }


                doOnUiThread {

                    val sleepDurationTemp = ((totalDuration- awakeDuration)*60*1000)
                    helper.setText(R.id.tvTotalDuration, TimeUtils.formatTime(sleepDurationTemp, showHour = true, showMin = true))

                    //睡眠时长
                    helper.setText(R.id.tvTotalDurationTip, when {
                        sleepDurationTemp < sleepDurationLowTemp -> getString(R.string.common_pressure_low_hint2)//低于
                        sleepDurationTemp > sleepDurationHighTemp -> getString(R.string.common_pressure_high_hint2)//高于
                        else -> getString(R.string.common_pressure_normal_hint)// 范围内[low, high]
                    })

                    helper.setTextColor(R.id.tvTotalDurationTip, when {
                        sleepDurationTemp < sleepDurationLowTemp -> getColor(R.color.c_ff9f40)//低于
                        sleepDurationTemp > sleepDurationHighTemp -> getColor(R.color.c_f3607b)//高于
                        else -> getColor(R.color.product_color)// 范围内[low, high]
                    })

                    //卧床时长
                    val theDayStayBedDurationTemp = theDayStayBedDuration*60000
                    helper.setText(R.id.tvStayDuration, TimeUtils.formatTime(theDayStayBedDurationTemp, showHour = true, showMin = true))
                    helper.setText(R.id.tvStayDurationTip, when {
                        theDayStayBedDurationTemp < sleepDurationLowTemp -> getString(R.string.common_pressure_low_hint2)//低于
                        theDayStayBedDurationTemp > sleepDurationHighTemp -> getString(R.string.common_pressure_high_hint2)//高于
                        else -> getString(R.string.common_pressure_normal_hint)// 范围内[low, high]
                    })

                    helper.setTextColor(R.id.tvStayDurationTip, when {
                        theDayStayBedDurationTemp < sleepDurationLowTemp -> getColor(R.color.c_ff9f40)//低于
                        theDayStayBedDurationTemp > sleepDurationHighTemp -> getColor(R.color.c_f3607b)//高于
                        else -> getColor(R.color.product_color)// 范围内[low, high]
                    })
                    //睡眠效率
                    helper.setText(R.id.tvSleepEfficiency, "$theDaySleepEfficiency${getString(R.string.common_bfb_unit)}")
                    helper.setText(R.id.tvSleepEfficiencyTip, when {
                        theDaySleepEfficiency < sleepEfficiencyLowTemp -> getString(R.string.common_pressure_low_hint2)//低于
                        theDaySleepEfficiency > sleepEfficiencyHighTemp -> getString(R.string.common_pressure_high_hint2)//高于
                        else -> getString(R.string.common_pressure_normal_hint)// 范围内[low, high]
                    })

                    helper.setTextColor(R.id.tvSleepEfficiencyTip, when {
                        theDaySleepEfficiency < sleepEfficiencyLowTemp -> getColor(R.color.c_ff9f40)//低于
                        theDaySleepEfficiency > sleepEfficiencyHighTemp -> getColor(R.color.c_f3607b)//高于
                        else -> getColor(R.color.product_color)// 范围内[low, high]
                    })

                    sleepStageChart.setSleepStageData(sleepData)
                    helper.setText(R.id.tvTimeOne,points[0])
                    helper.setText(R.id.tvTimeTwo,points[1])
                    helper.setText(R.id.tvTimeThree,points[2])
                    helper.setText(R.id.tvTimeFour,points[3])
                    helper.setText(R.id.tvTimeFive,points[4])


                    helper.getView<SleepOptimalRangeProgressBar>(R.id.spbAwake).apply {//清醒进度条
                        setProgress(((awakeDuration.toFloat() / totalDuration) * 100f).toInt())
                        // 设置最佳区间
                        setOptimalRange(0.5f, 10f)
                    }
                    helper.getView<SleepOptimalRangeProgressBar>(R.id.spbRem).apply {//快速眼动进度条
                        setProgress(((remDuration.toFloat() / totalDuration) * 100f).toInt())
                        // 设置最佳区间
                        setOptimalRange(20f,25f)
                    }
                    helper.getView<SleepOptimalRangeProgressBar>(R.id.spbLight).apply {//浅睡进度条
                        setProgress(((lightDuration.toFloat() / totalDuration) * 100f).toInt())
                        // 设置最佳区间
                        setOptimalRange(50f,60f)
                    }
                    helper.getView<SleepOptimalRangeProgressBar>(R.id.spbDeep).apply {//深睡进度条
                        setProgress(((deepDuration.toFloat() / totalDuration) * 100f).toInt())
                        // 设置最佳区间
                        setOptimalRange(15f, 25f)
                    }

                    helper.setText(R.id.tvAwakeDuration,TimeUtils.formatTime((awakeDuration*60*1000), showHour = true, showMin = true))
                    helper.setText(R.id.tvRemDuration,TimeUtils.formatTime((remDuration*60*1000), showHour = true, showMin = true))
                    helper.setText(R.id.tvLightDuration,TimeUtils.formatTime((lightDuration*60*1000), showHour = true, showMin = true))
                    helper.setText(R.id.tvDeepDuration,TimeUtils.formatTime((deepDuration*60*1000), showHour = true, showMin = true))
                }

            }
        }
    }

    override fun onViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        tvSleepHrAverage = viewHolder.getView(R.id.tvSleepHrAverage)
        tvSleepHrPast7nights = viewHolder.getView(R.id.tvSleepHrPast7nights)

        sleepHrCurveChart = viewHolder.getView(R.id.sleepHrCurveChart)
        sleepHrCurveChart?.setXAxisSolidLineEnabled(true)
        // 设置触摸监听
        sleepHrCurveChart?.setOnBarTouchListener(object : SleepHrCurveChart.OnBarTouchListener {
            override fun onBarTouched(
                index: Int,
                minValue: Float,
                maxValue: Float,
                timeLabel: String
            ) {
                SpanUtils.create()
                    .addSection(maxValue.toInt().toString())
//                    .addSection(hrSplice)
                    .addForeColorSection(hrSpliceHint, getColor(R.color.c_7f7f7f))
                    .setAbsSize(hrSpliceHint, 14)
                    .setStyle(hrSpliceHint, Typeface.NORMAL)
                    .showIn(viewHolder.getView(R.id.tvHrTouchValue))

                sleepHrCurveChart?.let {
                    viewHolder.setText(R.id.tvHrTouchValueHint,"${TimeUtils.getHourMinute(it.getData()[index].createdTime)}-${TimeUtils.getHourMinute(it.getData()[index].endTime)}")
                }

                viewHolder.setVisible(R.id.totalHrTouchValue, true)
            }

            override fun onTouchReleased() {
                // 处理触摸释放事件
                viewHolder.setVisible(R.id.totalHrTouchValue, false)
            }
        })

        tvSleepHrvAverage = viewHolder.getView(R.id.tvSleepHrvAverage)
        tvSleepHrvPast7nights = viewHolder.getView(R.id.tvSleepHrvPast7nights)
        sleepHrvCandlestickChart = viewHolder.getView(R.id.sleepHrvCandlestickChart)
        sleepHrvCandlestickChart?.setXAxisSolidLineEnabled(true)
        // 设置触摸监听
        sleepHrvCandlestickChart?.setOnBarTouchListener(object : SleepHrvCandlestickChart.OnBarTouchListener {
            override fun onBarTouched(
                index: Int,
                minValue: Float,
                maxValue: Float,
                timeLabel: String
            ) {
                SpanUtils.create()
                    .addSection("${minValue.toInt()}~${maxValue.toInt()}")
//                    .addSection(hrSplice)
                    .addForeColorSection(hrSpliceHint, getColor(R.color.c_7f7f7f))
                    .setAbsSize(hrSpliceHint, 14)
                    .setStyle(hrSpliceHint, Typeface.NORMAL)
                    .showIn(viewHolder.getView(R.id.tvHrvTouchValue))

                sleepHrvCandlestickChart?.let {
                    viewHolder.setText(R.id.tvHrvTouchValueHint,"${TimeUtils.getHourMinute(it.getData()[index].createdTime)}-${TimeUtils.getHourMinute(it.getData()[index].endTime)}")
                }

                viewHolder.setVisible(R.id.totalHrvTouchValue, true)
            }

            override fun onTouchReleased() {
                // 处理触摸释放事件
                viewHolder.setVisible(R.id.totalHrvTouchValue, false)
            }
        })


        tvSleepOxyAverage = viewHolder.getView(R.id.tvSleepOxyAverage)
        tvSleepOxyPast7nights = viewHolder.getView(R.id.tvSleepOxyPast7nights)
        sleepOxyCurveChart = viewHolder.getView(R.id.sleepOxyCurveChart)
        sleepOxyCurveChart?.setXAxisSolidLineEnabled(true)

        tvTempTheDayAverage = viewHolder.getView(R.id.tvTempTheDayAverage)
        tvRefTemp = viewHolder.getView(R.id.tvRefTemp)
        tvTempDif = viewHolder.getView(R.id.tvTempDif)

        tvResRateAverage = viewHolder.getView(R.id.tvResRateAverage)
        tvResRateScope = viewHolder.getView(R.id.tvResRateScope)
        tvResRateAvg7days = viewHolder.getView(R.id.tvResRateAvg7days)

        tvSleepHrAverage?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$averageSpliceHint", 14)
                .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                .showIn(this)
        }
        tvSleepHrPast7nights?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$sevenDayAverageHint", 14)
                .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                .showIn(this)
        }

        tvSleepHrvAverage?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$averageSpliceHint", 14)
                .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                .showIn(this)
        }
        tvSleepHrvPast7nights?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$sevenDayAverageHint", 14)
                .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                .showIn(this)
        }

        tvSleepOxyAverage?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$averageSpliceHint", 14)
                .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                .showIn(this)
        }
        tvSleepOxyPast7nights?.apply {
            SpanUtils.create()
                .addSection(getString(R.string.common_rail_unit))
                .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                .setAbsSize("\n$sevenDayAverageHint", 14)
                .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                .showIn(this)
        }


        super.onViewHolderCreated(viewHolder, viewType)
    }

    private fun initClassDuration(){
        totalDuration = 0L//睡眠总时长，单位：分钟
        awakeDuration = 0//清醒时长，单位：分钟
        lightDuration = 0//浅睡时长，单位：分钟
        remDuration = 0//快速眼动时长，单位：分钟
        deepDuration = 0//深睡时长，单位：分钟
    }

    /**
     * 获取当天心率
     */
    private fun getSleepTheDayHr(startTime:Long, endTime:Long){
        if (startTime <=0 ||endTime <=0) return

        //睡眠心率
        HeartRateRepo.instance.findByTimeRange(startTime, endTime)?.let {listIt->
            if (listIt.isNullOrEmpty()) return

            val listItStr = JsonUtils.toJson(listIt)
            // 创建48个时间区间块的CusChartData数组
            val sleepHrData = mutableListOf<CusChartData>()
            val timeDuration = endTime - startTime
            val intervalDuration = timeDuration / 48 // 每个时间区间的时长

            // 初始化48个时间区间块
            for (i in 0 until 48) {
                val intervalStartTime = startTime + (i * intervalDuration)
                val intervalEndTime = startTime + ((i + 1) * intervalDuration)
                sleepHrData.add(
                    CusChartData(
                        createdTime = intervalStartTime,
                        endTime = intervalEndTime,
                        minValue = 0f,
                        mValue = 0f,
                        dayNum = 0
                    )
                )
            }

            val sleepHrDataInitStr = JsonUtils.toJson(sleepHrData)

            // 将listIt数组的数据根据createdTime分配到对应的时间区间块
            listIt.sortedBy { it.createdTime }.forEach { heartRateData ->
                // 计算该心率数据属于哪个时间区间块
                val timeOffset = heartRateData.createdTime - startTime
                val intervalIndex = (timeOffset / intervalDuration).toInt()

                // 确保索引在有效范围内
                if (intervalIndex in 0 until 48) {
                    val currentData = sleepHrData[intervalIndex]
                    // 将心率值累加到对应区间块的mValue中
                    if (currentData.mValue == 0f) {
                        // 如果是第一个数据，直接赋值
                        currentData.mValue = heartRateData.heartRate.toFloat()
                    } else {
                        // 如果已有数据，可以选择取平均值或最大值等策略
                        // 这里采用平均值策略
                        currentData.mValue = (currentData.mValue + heartRateData.heartRate.toFloat()) / 2f
                    }
                }
            }

            val minTemp = ((listIt.minOfOrNull { it.heartRate } ?: 30f).toFloat())
            val maxTemp = ((listIt.maxOfOrNull { it.heartRate } ?: 125f).toFloat())
            val theDayAverage = if (listIt.isNotEmpty()) {//当日平均
                listIt.map { it.heartRate }.average().toInt()
            } else {
                60f
            }

//            val sleepHrDataStr = JsonUtils.toJson(sleepHrData)

            doOnUiThread {
                tvSleepHrAverage?.apply {
                    SpanUtils.create()
                        .addSection(theDayAverage.toInt().toString())
                        .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                        .setAbsSize("\n$averageSpliceHint", 14)
                        .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                        .showIn(this)
                }

                sleepHrCurveChart?.setYRangeBackground(startValue = 55f,endValue = 65f,backgroundColor = getColor(R.color.c_f7ebf2))
                // 设置Y轴阶段
                sleepHrCurveChart?.setYAxisStages(
                    floatArrayOf(minTemp-10f, ((maxTemp-minTemp)/2).toInt()+minTemp, maxTemp+10f), // 阶段分界点
                )

                sleepHrCurveChart?.setData(sleepHrData)
            }

        }
    }

    /**
     * 获取近7天睡眠心率数据并构建时间段数组
     */
    private fun getSevenNightsDayHr(){
        if (curTime <=0 ) return
        doOnIOThread {
            val timeRanges = mutableListOf<Pair<Long, Long>>()
//            for (day in 2..8) {// 获取前7天的时间范围（不包含今天）
            for (day in 1..7) {// 获取前7天的时间范围（含今天）
                val timeRange = TimeUtils.getTimeRangeForSleep(curTime, day)
                timeRanges.add(timeRange)
            }

            val timeRangesStr = JsonUtils.toJson(timeRanges)

            // 使用构建的timeRanges查询多时间段数据
            HeartRateRepo.instance.findByMultiTimeRanges(timeRanges)?.let { hrOriginalListIt->
//                val hrOriginalListItStr = JsonUtils.toJson(hrOriginalListIt)

                val sevenDayAverage = if (hrOriginalListIt.isNotEmpty()) {//7日平均
                    hrOriginalListIt.map { it.heartRate }.average().toInt()
                } else {
                    -1
                }

                if (sevenDayAverage>0){
                    sleepHrCurveChart?.setBasicValue(sevenDayAverage.toFloat())
                }

                doOnUiThread {
                    tvSleepHrPast7nights?.apply {
                        SpanUtils.create()
                            .addSection(if (hrOriginalListIt.isNotEmpty()) {//近7天睡眠心率平均
                                hrOriginalListIt.map { it.heartRate }.average().toInt().toString()
                            } else {
                                getString(R.string.common_rail_unit)
                            })
                            .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                            .setAbsSize("\n$sevenDayAverageHint", 14)
                            .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                            .showIn(this)
                    }
                }
            }
        }
    }

    /**
     * 获取当天心率变异性
     */
    private fun getTheDayHrvData(startTime: Long, endTime: Long,){
        if (curTime <=0 ) return
        getSevenNightsDayHrv()

        doOnIOThread {
            HeartRateVariabilityRepo.instance.findByTimeRange(startTime, endTime)?.let { hrvOriginalListIt ->

                if (hrvOriginalListIt.isNullOrEmpty()) return@doOnIOThread

                val listItStr = JsonUtils.toJson(hrvOriginalListIt)

                // 创建48个时间区间块的CusChartData数组
                val sleepHvrData = mutableListOf<CusChartData>()
                val timeDuration = endTime - startTime
                val intervalDuration = timeDuration / 48 // 每个时间区间的时长

                // 初始化48个时间区间块
                for (i in 0 until 48) {
                    val intervalStartTime = startTime + (i * intervalDuration)
                    val intervalEndTime = startTime + ((i + 1) * intervalDuration)
                    sleepHvrData.add(
                        CusChartData(
                            createdTime = intervalStartTime,
                            endTime = intervalEndTime,
                            minValue = 0f,
                            mValue = 0f,
                            dayNum = 0
                        )
                    )
                }

                val sleepHrvDataInitStr = JsonUtils.toJson(sleepHvrData)

                var isAllEmpty = true

                hrvOriginalListIt.forEach {
                    if (it.heartRateVariability>0){
                        isAllEmpty = false
                        return@forEach
                    }
                }

                if (isAllEmpty) return@doOnIOThread

                // 将hrvOriginalListIt数组的数据根据createdTime分配到对应的时间区间块
                hrvOriginalListIt.sortedBy { it.createdTime }.forEach { heartRateData ->
                    // 计算该心率数据属于哪个时间区间块
                    val timeOffset = heartRateData.createdTime - startTime
                    val intervalIndex = (timeOffset / intervalDuration).toInt()

                    // 确保索引在有效范围内
                    if (intervalIndex in 0 until 48) {
                        val currentInterval = sleepHvrData[intervalIndex]
                        val heartRate = heartRateData.heartRateVariability.toFloat()

                        // 如果是该区间的第一个数据点，直接设置最大值和最小值
                        if (currentInterval.mValue == 0f && currentInterval.minValue == 0f) {
                            sleepHvrData[intervalIndex] = currentInterval.copy(
                                mValue = heartRate,
                                minValue = heartRate
                            )
                        } else {
                            // 更新最大值和最小值
                            sleepHvrData[intervalIndex] = currentInterval.copy(
                                mValue = maxOf(currentInterval.mValue, heartRate),
                                minValue = if (currentInterval.minValue == 0f) heartRate else minOf(currentInterval.minValue, heartRate)
                            )
                        }
                    }
                }

                val minTemp = ((hrvOriginalListIt.minOfOrNull { it.heartRateVariability } ?: -1f).toFloat())
                val maxTemp = ((hrvOriginalListIt.maxOfOrNull { it.heartRateVariability } ?: -1f).toFloat())
                val theDayAverage = if (hrvOriginalListIt.isNotEmpty()) {//当日平均
                    hrvOriginalListIt.map { it.heartRateVariability }.average().toInt()
                } else {
                    60f
                }

                // 在UI线程中更新图表
                doOnUiThread {

                    tvSleepHrvAverage?.apply {
                        SpanUtils.create()
                            .addSection(theDayAverage.toInt().toString())
                            .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                            .setAbsSize("\n$averageSpliceHint", 14)
                            .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                            .showIn(this)
                    }

                    // 设置Y轴阶段
                    sleepHrvCandlestickChart?.setYAxisStages(
                        floatArrayOf(minTemp-10f, ((maxTemp-minTemp)/2).toInt()+minTemp, maxTemp+10f), // 阶段分界点
                    )

                    sleepHrvCandlestickChart?.setData(sleepHvrData)
                }
            }
        }
    }

    /**
     * 获取近7天睡眠心率变异性数据并构建时间段数组
     */
    private fun getSevenNightsDayHrv(){
        if (curTime <=0 ) return
        doOnIOThread {
            val timeRanges = mutableListOf<Pair<Long, Long>>()
//            for (day in 2..8) {// 获取前7天的时间范围（不包含今天）
            for (day in 1..7) {// 获取前7天的时间范围（含今天）
                val timeRange = TimeUtils.getTimeRangeForSleep(curTime, day)
                timeRanges.add(timeRange)
            }

            // 使用构建的timeRanges查询多时间段数据
            HeartRateVariabilityRepo.instance.findByMultiTimeRanges(timeRanges)?.let { hrOriginalListIt->

                val sevenDayAverage = if (hrOriginalListIt.isNotEmpty()) {//平均
                    hrOriginalListIt.map { it.heartRateVariability }.average().toInt()
                } else {
                    -1
                }

                if (sevenDayAverage>0){
                    sleepHrvCandlestickChart?.setBasicValue(sevenDayAverage.toFloat())
                }

                doOnUiThread {
                    tvSleepHrvPast7nights?.apply {
                        SpanUtils.create()
                            .addSection(if (hrOriginalListIt.isNotEmpty()) {//近7天睡眠心率变异平均
                                hrOriginalListIt.map { it.heartRateVariability }.average().toInt().toString()
                            } else {
                                getString(R.string.common_rail_unit)
                            })
                            .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                            .setAbsSize("\n$sevenDayAverageHint", 14)
                            .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                            .showIn(this)
                    }
                }
            }
        }
    }

    /**
     * 获取当天血氧
     */
    private fun getTheDayOxyData(startTime:Long, endTime:Long){
        if (startTime <=0 ||endTime <=0) return
        getSevenNightsDayOxy()
        //睡眠血氧
        BloodOxygenRepo.instance.findByTimeRange(startTime, endTime)?.let {listIt->
            if (listIt.isNullOrEmpty()) return

            val listItStr = JsonUtils.toJson(listIt)
            // 创建48个时间区间块的CusChartData数组
            val sleepOxyData = mutableListOf<CusChartData>()
            val timeDuration = endTime - startTime
            val intervalDuration = timeDuration / 48 // 每个时间区间的时长

            // 初始化48个时间区间块
            for (i in 0 until 48) {
                val intervalStartTime = startTime + (i * intervalDuration)
                val intervalEndTime = startTime + ((i + 1) * intervalDuration)
                sleepOxyData.add(
                    CusChartData(
                        createdTime = intervalStartTime,
                        endTime = intervalEndTime,
                        minValue = 0f,
                        mValue = 0f,
                        dayNum = 0
                    )
                )
            }

            val sleepHrDataInitStr = JsonUtils.toJson(sleepOxyData)

            // 将listIt数组的数据根据createdTime分配到对应的时间区间块
            listIt.sortedBy { it.createdTime }.forEach { heartRateData ->
                // 计算该心率数据属于哪个时间区间块
                val timeOffset = heartRateData.createdTime - startTime
                val intervalIndex = (timeOffset / intervalDuration).toInt()

                // 确保索引在有效范围内
                if (intervalIndex in 0 until 48) {
                    val currentData = sleepOxyData[intervalIndex]
                    // 将心率值累加到对应区间块的mValue中
                    if (currentData.mValue == 0f) {
                        // 如果是第一个数据，直接赋值
                        currentData.mValue = heartRateData.bloodOxygen.toFloat()
                    } else {
                        // 如果已有数据，可以选择取平均值或最大值等策略
                        // 这里采用平均值策略
                        currentData.mValue = (currentData.mValue + heartRateData.bloodOxygen.toFloat()) / 2f
                    }
                }
            }

            val minTemp = ((listIt.minOfOrNull { it.bloodOxygen } ?: 60f).toFloat())
            val maxTemp = ((listIt.maxOfOrNull { it.bloodOxygen } ?: 100f).toFloat())
            val theDayAverage = if (listIt.isNotEmpty()) {//当日平均
                listIt.map { it.bloodOxygen }.average().toInt()
            } else {
                60f
            }

            val sleepHrDataStr = JsonUtils.toJson(sleepOxyData)
            doOnUiThread {

                tvSleepOxyAverage?.apply {
                    SpanUtils.create()
                        .addSection(theDayAverage.toInt().toString())
                        .addForeColorSection("\n$averageSpliceHint", getColor(R.color.c_7f7f7f))
                        .setAbsSize("\n$averageSpliceHint", 14)
                        .setStyle("\n$averageSpliceHint", Typeface.NORMAL)
                        .showIn(this)
                }

                sleepOxyCurveChart?.setYRangeBackground(startValue = 95f,endValue = 100f,backgroundColor = getColor(R.color.c_f7ebf2))
                // 设置Y轴阶段
                sleepOxyCurveChart?.setYAxisStages(
                    floatArrayOf(minTemp-10f, ((maxTemp-minTemp)/2).toInt()+minTemp, maxTemp+10f), // 阶段分界点
                )

                sleepOxyCurveChart?.setData(sleepOxyData)
            }

        }
    }

    /**
     * 获取近7天睡眠血氧数据并构建时间段数组
     */
    private fun getSevenNightsDayOxy(){
        if (curTime <=0 ) return
        doOnIOThread {
            val timeRanges = mutableListOf<Pair<Long, Long>>()
            for (day in 1..7) {// 获取前7天的时间范围（含今天）
                val timeRange = TimeUtils.getTimeRangeForSleep(curTime, day)
                timeRanges.add(timeRange)
            }

            // 使用构建的timeRanges查询多时间段数据
            BloodOxygenRepo.instance.findByMultiTimeRanges(timeRanges)?.let { hrOriginalListIt->

                val sevenDayAverage = if (hrOriginalListIt.isNotEmpty()) {//平均
                    hrOriginalListIt.map { it.bloodOxygen }.average().toInt()
                } else {
                    -1
                }

                if (sevenDayAverage>0){
                    sleepOxyCurveChart?.setBasicValue(sevenDayAverage.toFloat())
                }

                doOnUiThread {
                    tvSleepOxyPast7nights?.apply {
                        SpanUtils.create()
                            .addSection(if (hrOriginalListIt.isNotEmpty()) {//近7天平均
                                hrOriginalListIt.map { it.bloodOxygen }.average().toInt().toString()
                            } else {
                                getString(R.string.common_rail_unit)
                            })
                            .addForeColorSection("\n$sevenDayAverageHint", getColor(R.color.c_7f7f7f))
                            .setAbsSize("\n$sevenDayAverageHint", 14)
                            .setStyle("\n$sevenDayAverageHint", Typeface.NORMAL)
                            .showIn(this)
                    }
                }
            }
        }
    }

    /**
     * 获取当天体温
     */
    private fun getTheDayBodyTempData(startTime:Long, endTime:Long){
        if (startTime <=0 ||endTime <=0) return

        get30DayBodyTempData(0)

        //睡眠体温
        BodyTemperatureRepo.instance.findByTimeRange(startTime, endTime)?.let {listIt->

            if (listIt.isNullOrEmpty()) return

            val theDayAverage = if (listIt.isNotEmpty()) {//当日平均
                listIt.map { it.bodyTemperature }.average().toInt()
            } else {
                0f
            }

            get30DayBodyTempData(theDayAverage)

            doOnUiThread {
                tvTempTheDayAverage?.text = theDayAverage.toString()
            }

        }
    }

    /**
     * 获取30天体温
     */
    private fun get30DayBodyTempData(theDayAverage:Number){

        //睡眠体温
        BodyTemperatureRepo.instance.findLast7DaysFromTimestamp(curTime)?.let {listIt->
            if (listIt.isNullOrEmpty()) return

            val mDayAverage = if (listIt.isNotEmpty()) {//平均
                listIt.map { it.bodyTemperature }.average().toInt()
            } else {
                35f
            }

            doOnUiThread {
                tvRefTemp?.text = mDayAverage.toString()
                tvTempDif?.text = (theDayAverage.toFloat()- mDayAverage.toFloat()).toString()
            }

        }
    }

    /**
     * 获取当天呼吸率
     */
    private fun getTheDayResRateData(startTime:Long, endTime:Long){
        if (startTime <=0 ||endTime <=0) return

        get7DayResRateData(0)

        //睡眠呼吸率
        RespiratoryRateRepo.instance.findByTimeRange(startTime, endTime)?.let {listIt->

            if (listIt.isNullOrEmpty()) return

            val theDayAverage = if (listIt.isNotEmpty()) {//当日平均
                listIt.map { it.bpm }.average().toInt()
            } else {
                0f
            }

            get7DayResRateData(theDayAverage)

            doOnUiThread {
                tvResRateAverage?.text = theDayAverage.toString()
            }

        }
    }


    /**
     * 获取7天呼吸率
     */
    private fun get7DayResRateData(theDayAverage:Number){

        //睡眠呼吸率
        RespiratoryRateRepo.instance.findLast7DaysFromTimestamp(curTime)?.let {listIt->
            if (listIt.isNullOrEmpty()) return

            val mDayAverage = if (listIt.isNotEmpty()) {//平均
                listIt.map { it.bpm }.average().toInt()
            } else {
                35f
            }

            doOnUiThread {
                tvResRateScope?.text = mDayAverage.toString()
                tvResRateAvg7days?.text = (theDayAverage.toFloat()- mDayAverage.toFloat()).toString()
            }

        }
    }
}